home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MVUPDAT3.ZIP / WORDTOOL.ZIP / DECWORD.C next >
Encoding:
C/C++ Source or Header  |  1996-09-02  |  7.6 KB  |  183 lines

  1. /*********
  2.   (c) AURODREPH Productions 04/1996
  3. **********/
  4.  
  5. #include "io.h"
  6. #include "stdlib.h"
  7. #include "stdio.h"
  8. #include "conio.h"
  9. #include "process.h"
  10. #include "fcntl.h"
  11. #include "string.h"
  12. #include "sys\stat.h"
  13.  
  14. void main (void)
  15.  {
  16.         char Name[13];
  17.         char Target[13];
  18.         unsigned char *Buffer;
  19.         int Handler, Handler1;
  20.         unsigned int Offset;
  21.         unsigned long Length = 0;
  22.         int point, max, trouve, cledec, debmac, decfin;
  23.         int stop,nbr,positcle,nbrmac,i;
  24.  
  25.         clrscr();
  26.         printf (" ******************************************************************\n");
  27.         printf (" *                                                                *\n");
  28.         printf (" *               DECRYPT WORD 6.0 MACROS saved                    *\n");
  29.         printf (" *                 with the option Execute-only                   *\n");
  30.         printf (" *                                                                *\n");
  31.         printf (" *                                                                *\n");
  32.         printf (" *       --- ,This file works only with files < 32 Ko. ----       *\n");
  33.         printf (" *     <*****}===============-                                    *\n");
  34.         printf (" *      (z)  ' AURODREPH Productions 04/1996                      *\n");
  35.         printf (" *                                                     ver 0.666B *\n");
  36.         printf (" ******************************************************************\n");
  37.         printf ("\n"); printf("\n");
  38.         printf ("Name of the input file     = ");
  39.         scanf ("%12s",Name);
  40.         printf ("\n");
  41.         printf ("Name of the output file    = ");
  42.         scanf ("%12s",Target);
  43.         printf("\n");
  44.         printf ("Number of crypted macros   = ");
  45.         scanf ("%d",&nbrmac);
  46.         printf("\n");
  47.         if (nbrmac > 50 ) {exit (0);}
  48.         Handler = open (Name, O_BINARY | O_RDONLY , S_IREAD);
  49.         if (Handler == -1)
  50.                 {printf ("The input file doesn't exist.\n"); exit(0);}
  51.  
  52.         Length = (unsigned long) lseek(Handler, 0, SEEK_END);
  53.         lseek (Handler,0,SEEK_SET);
  54.         Buffer = (unsigned char *) malloc((unsigned) Length);
  55.         if (Buffer == NULL) printf ("Fail memory allocation.\n");
  56.         if (read(Handler, Buffer, (unsigned) Length) != Length)
  57.                 {printf ("The size of the file is > 32 ko)\n");
  58.                  printf ("Try to remove some macros with WORD....\n");
  59.                  exit (0);}
  60.  
  61.         point = 0;
  62.         max = strlen(Name);
  63.         trouve = 1;
  64.         cledec = 0x00;
  65.         debmac = 0x00;
  66.         stop = 0;
  67.         for (i=0; i<max;i++)
  68.                 {if ((Name[i]>= 0x61) & (Name[i]<= 0x7A))
  69.                          { Name[i] = Name[i] & 0xDF ;}
  70.                 };
  71.  
  72.         for (Offset = 0x0000; Offset < Length; Offset++)
  73.          {
  74.           if ((Buffer[Offset] == Name[point]) && (stop !=1))
  75.                         {
  76.                         for (point = 1; point <= (max-1); point++)
  77.                                  {if (Buffer [Offset+point] == Name[point])
  78.                                                         { trouve = trouve+1; }                                                  }
  79.                                                         else trouve = 1;
  80.                                  };
  81.                         }
  82.           if (trouve == max) {stop = 1;}
  83.           if ((trouve == max) && (Buffer[Offset] == 0x55))
  84.                         {cledec = Buffer[Offset+1];
  85.                         trouve = 0;
  86.                         Buffer [Offset+1] = 0x00;
  87.                         positcle = Offset;
  88.                         }
  89.           point = 0;
  90.          };
  91. if (cledec == 0x00)
  92.         {printf (" Don't find the decrypted key... \n"); exit (0);}
  93.         else printf ("Decrypted Key for the macro n 1 = %x \n", cledec);
  94.  
  95.         for (Offset = 0x0000; Offset < Length; Offset++)
  96.          {
  97.           if (Buffer[Offset] == 0xA5)
  98.           {if ((Buffer [Offset+1] == 0xC6) || (Buffer [Offset+1] == 0xC4))
  99.                   {if (Buffer [Offset+2] == 0x41)
  100.                           {if (Buffer [Offset+4] == cledec)
  101.                                         {debmac = Offset+3;
  102.                                         }
  103.                           }       }       }      };
  104. if (debmac == 0x00)
  105.                 {for (Offset = 0x0000; Offset < Length; Offset++)
  106.                                  {
  107.                                  if (Buffer[Offset] == cledec-1)
  108.                                         {if (Buffer [Offset+1] == cledec)
  109.                                                {debmac = Offset;  }
  110.                                                 }        };             }
  111. if (debmac == 0x00) { printf (" Don't find the beginning of the macro\n");      exit(0);}
  112.  
  113.  
  114. for (nbr = 1 ; nbr <= nbrmac ;nbr++)
  115. {
  116. if (nbr != 1)
  117.         {
  118.         printf ("\n");
  119.         printf (" I decrypt the macro n %d \n", nbr);
  120.         Offset = positcle+24;
  121.          if (Buffer[Offset] ==  0x55)
  122.                         {cledec = Buffer [Offset+1];
  123.                         Buffer [Offset+1] = 0x00;
  124.                         positcle = Offset;
  125.            printf ("Decrypted Key for the macro n %d = %x \n", nbr,cledec);
  126.                                 }
  127.                         else
  128.                     {printf (" Don't find the decrypted key ....\n");}
  129.         }
  130. Offset = debmac;
  131. point = 0;
  132. decfin = 1;
  133. stop = 1;
  134. printf ( " I work ");
  135.         do
  136.         { if (stop == 400) {printf ("."); stop = 1 ;}
  137.           Buffer[Offset+point] ^= cledec ; /* decryptage par XOR */
  138.  
  139.           if (Buffer [Offset+point] == 0x64)
  140.                                 {Buffer [Offset+point+1] ^= cledec;
  141.                                 if (Buffer [Offset+point+1] == 0x1a)
  142.                                         {Buffer [Offset+point+2] ^= cledec;
  143.                                                 if (Buffer [Offset+point+2] == 0x1b)
  144.                                                         {Buffer [Offset+point+3] ^= cledec;
  145.                                                         if (Buffer [Offset+point+3] != 0x64)
  146.                                                                  {decfin = 0;
  147.                                                                  debmac = Offset+point+3;
  148.                                                                  Buffer [Offset+point+3] ^= cledec;
  149.                                                                  }
  150.                                                         else
  151.                                                                  Buffer [Offset+point+3] ^= cledec;
  152.                                                         }
  153.                                                 else
  154.                                                         Buffer [Offset+point+2] ^= cledec;
  155.                                 }
  156.                                 else
  157.                                          Buffer [Offset+point+1] ^= cledec;
  158.                 }
  159.         if ((Offset+point) == Length) {decfin = 0;}
  160.  
  161.         stop = stop + 1;
  162.         point = point + 1;
  163.         }
  164.         while ( ( decfin != 0) );
  165. printf ("\n");
  166. printf (" End of decrypting the macro n %d \n", nbr);
  167. };
  168.  
  169.         _fmode= O_BINARY;
  170.  
  171.         Handler1 = creat(Target, S_IFMT | S_IREAD | S_IWRITE);
  172.         write (Handler1, Buffer,(unsigned) Length);
  173.  
  174.         close (Handler1);
  175.         close (Handler);
  176.         printf ("\n"); printf ("\n");
  177.         printf (" END ... \n");
  178.         printf ("\n");
  179.         printf (" The decrypted file is  %s .\n", Target);
  180. }
  181.  
  182. - ------------------><--- cut here ------------------------------------
  183.